package kr.moiba.vertification.dao.impl;

import java.util.List;
import java.util.Map;

import kr.moiba.vertification.dao.VertificationDao;
import kr.moiba.vertification.domain.Vertification;

import org.apache.ibatis.session.RowBounds;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository;

/**
 * @author Lee Youngho
 *
 */

@Repository
public class VertificationDaoImpl extends SqlSessionDaoSupport  implements VertificationDao {

	public VertificationDaoImpl() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public List<Vertification> SelectList(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Integer page = (Integer)condition.get("page");
		Integer maxnum = (Integer)condition.get("maxnum");
		
		List<Vertification> result = null;
		if(page != null && maxnum != null){
			RowBounds rb = new RowBounds(page, maxnum);
			result = getSqlSession().selectList("Vertification.selectList", condition, rb);
		}else{
			result = getSqlSession().selectList("Vertification.selectList", condition);
		}
		
		return result;
	}
	
	@Override
	public Integer SelectListTotalCnt(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Integer result = getSqlSession().selectOne("Vertification.selectListTotalCnt", condition);
		return result;
	}
	
	@Override
	public List<Map<String, Object>> SelectListResult(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		List<Map<String, Object>> result = getSqlSession().selectList("Vertification.selectList.result", condition);
		return result;
	}

	@Override
	public Vertification select(Integer idx) throws Exception {
		// TODO Auto-generated method stub
		Vertification result = (Vertification)(getSqlSession().selectOne("Vertification.select", idx)); 
		return result;
	}

	@Override
	public Vertification insert(Vertification vertification) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().insert("Vertification.insert", vertification);
		return vertification;
	}

	@Override
	public Vertification update(Vertification vertification) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().update("Vertification.update", vertification);
		return vertification;
	}

	@Override
	public int delete(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().update("Vertification.delete", condition);
		return result;
	}

}
